package com.jhgsys.internal.sypq.controller;

import com.jhgsys.internal.common.annotation.Log;
import com.jhgsys.internal.common.controller.BaseController;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.entity.FebsResponse;
import com.jhgsys.internal.common.exception.FebsException;
import com.jhgsys.internal.sypq.entity.TaskTestcs;
import com.jhgsys.internal.sypq.entity.TaskTestlx;
import com.jhgsys.internal.sypq.service.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 试验内容 Controller
 *
 * @author ganjun
 * @date 2024-11-18 11:13:09
 */
@Slf4j
@Validated
@Controller
public class TaskTestlxController extends BaseController {

    @Autowired
    private ITaskTestlxService taskTestlxService;



    @GetMapping(FebsConstant.VIEW_PREFIX + "taskTestlx/row")
       public String taskTestEdit(Model model, TaskTestlx test){
            if(0==test.getId()){
                test.setId(null);
            }
        if("undefined".equals(test.getShipcode())){
            test.setShipcode(null);
        }
        if("undefined".equals(test.getDraugh())){
            test.setDraugh(null);
        }
        if("undefined".equals(test.getDisplacement())){
            test.setDisplacement(null);
        }
        if("undefined".equals(test.getSpeed())){
            test.setSpeed(null);
        }

        if("undefined".equals(test.getRemark())){
            test.setRemark(null);
        }
        model.addAttribute("taskTestlx",test);
        return jumpPage("sypq/taskTestlx/taskTestlxEdit");
    }



    @Log("修改TaskTest")
    @PostMapping("taskTestbl/update")
    @ResponseBody
    @RequiresPermissions("taskTest:edit")
    public FebsResponse updateTaskTest(TaskTestlx test) throws FebsException {
        try {
            if(test.getId()==null||test.getId()<1){
                taskTestlxService.createTaskTestlx(test);
            }else {
                taskTestlxService.updateTaskTestlx(test);
            }
            return success();
        } catch (Exception ex) {
            return failure(ex,"修改失败");
        }
    }




}
